package com.sogeti.mentormatch.aop.spring;

import java.lang.reflect.Method;

import com.sogeti.mentormatch.aop.QueryFinderNamingStrategy;

/**
 * @author Matthew L. Maurer <maurer.it@gmail.com>
 */
public class ExtendedQueryFinderNamingStrategy implements
    QueryFinderNamingStrategy
{

    public String getQueryNameFromMethodCall ( Class<?> targetToFindQueryFor,
            Method interceptedMethod )
    {
        String interceptedMethodName = interceptedMethod.getName();
        String queryName = interceptedMethodName;
        if(interceptedMethodName.startsWith("findBy")) {
            // No-op
        }
        else if(interceptedMethodName.startsWith("listBy")) {
            queryName = "findBy" + interceptedMethodName.substring("listBy".length());
        }
        else if(interceptedMethodName.startsWith("iterateBy")) {
            queryName = "findBy" + interceptedMethodName.substring("iterateBy".length());
        }
        else if(interceptedMethodName.startsWith("scrollBy")) {
            queryName = "findBy" + interceptedMethodName.substring("scrollBy".length());
        }
        return targetToFindQueryFor.getSimpleName() + "." + queryName;
    }

}
